package com.example.demo.service.impl;


import com.example.demo.dao.CourseCatDao;
import com.example.demo.entity.CourseCatBean;
import com.example.demo.service.CourseCatService;
import com.example.demo.util.PageEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseCatServiceImpl implements CourseCatService {

    @Autowired
    private CourseCatDao courseCatDao;

    @Override
    public List<CourseCatBean> all() {
        return courseCatDao.getAll();
    }

    @Override
    public Integer add(CourseCatBean courseCatBean) {
        return courseCatDao.insert(courseCatBean);
    }


    @Override
    public Integer update(CourseCatBean courseCatBean) {
        return courseCatDao.edit(courseCatBean);
    }

    @Override
    public Integer delete(Integer id) {
        return courseCatDao.del(id);
    }

    @Override
    public CourseCatBean one(Integer id) {
        return courseCatDao.getOne(id);
    }

    @Override
    public PageEntity list(Integer pageNo, Integer pageSize,String address,String name,String sortOrder) {

        // 根据页码 求 跳过多少条数据
        Integer jump = (pageNo-1)*pageSize;

        Integer count = courseCatDao.getCount(address, name);
        List<CourseCatBean> rows = courseCatDao.getPage(jump, pageSize, address, name, sortOrder);


        PageEntity<List> listPageEntity = new PageEntity<List>(rows,count);
        return listPageEntity;
    }


}

